<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>JSON入门</title>
    <script src="js/axios-0.18.0.js"></script>
</head>
<body>

<script>
    // JS对象
    let person = {
        userName: "齐天大圣",
        realName: "孙悟空",
        age: 501
    };
    document.write(person + ": " + person.userName + "<br/>");

    // JSON对象
    let person2 = {
        "userName": "齐天大圣",
        "realName": "孙悟空",
        "age": 501
    };
    document.write(person2 + ": " + person2.userName + "<br/>");
    // 注意: JS对象 == JSON对象

    // JSON字符串
    let person3 = '{"userName": "齐天大圣", "realName": "孙悟空", "age": 501}';

    document.write("=====================" + "<br/>");

    let person4 = {
        userName: "齐天大圣",
        realName: "孙悟空",
        age: 501
    };
    // 1.JS对象转为JSON字符串
    let jsonStr1 = JSON.stringify(person4);
    document.write(jsonStr1 + "<br/>");
    document.write("hehe" + "<br/>");

    // 2.定义JSON字符串
    let jsonStr = '{"username": "张三", "password": "123"}';

    // 3.将JSON字符串转为JS对象
    var jsonObject = JSON.parse(jsonStr);
    document.write(jsonObject + "<br/>");

    // Axios中，JSON字符串和JS对象自动进行转换

</script>
</body>
</html>